#/bin/env python2.7
#encoding:utf-8
from config.tdm_mongo_modules import *
db_connect('acard')
t = open('/home/qujianning/prj/tdm/tmp1.txt').readlines()
for i in t:
    venue_id, service_name, venue_name, ctm1, ctm2 = i.strip().split()
    print venue_id, service_name, venue_name, ctm1, ctm2
    v = Venue.objects(venue_id=venue_id).first()
    if not v:
        print 'venue %s not found' % venue_name
        continue
    for ctm in [ctm1, ctm2]:
        c = CtmDevice.objects(devid=ctm).first()
        if not c:
            print 'new ctm %s' % ctm
            c = CtmDevice(devid=ctm).save()
        if c:
            if ctm.find('_dm_') > 0:
                c.memo = '主机'
                c.save()
            elif ctm.find('_ds_') > 0:
                c.memo = '备机'
                c.save()
        if not c in v.ctm_devs:
            print 'add %s to %s' % (ctm, v.name)
            v.ctm_devs.append(c)
            v.save()
